package com.crl.utils
{
	import com.crl.core.config.IXMLBindable;
	

	public class XMLBindableUtil
	{
		public function XMLBindableUtil()
		{
			throw new Error("输助类");
		}
		
		
		/**
		 * 把一个xml绑定到一个对像上; 
		 * @param ins
		 * @param xml
		 * 
		 */		
		public static function bindXML(ins:Object,xml:XML):void{
			var item:XML;
			var attrs:XMLList=xml.attributes();
			
			var pro:String;
			for each(item in attrs){
				pro=item.localName();				
				if(ins.hasOwnProperty(pro)==false)continue;
				
				ins[pro]=item.toString();
			}
			
			
			var children:XMLList=xml.children();
			if(children.length()==0)return;
			
			for each(item in children){
				pro=item.localName();
				
				if(ins.hasOwnProperty(pro)==false)continue;
				
				if(ins[pro] is IXMLBindable){
					(ins[pro] as IXMLBindable).bindXML(item);
				}else{
					ins[pro]=item.text();
				}
			}
			
		}
	}
}